<?php
namespace Api\Controller;
use Common\Model\UserModel;
use Common\Model\UserInfoModel;
use Common\Model\LogModel;
use Org\User\Verification;
use Common\Model\UserTokenModel;
use Common\Model\UserCodeModel;
use Think\Verify;
use Api\Model\UserCustomerModel;

/**
 * 用户相关操作的控制器，用来控制用户的一些相关信息
 * 
 * @author xiaoyutab<xiaoyutab@qq.com>
 * @adtime 2018-03-15 17:46:27
 * @version v1.0.0
 * @copyright (c) 2017, xiaoyutab
 */
class UserController extends ApiController {

    /**
     * 用户注册操作
     * 		传输方式：POST
     * 		返回参数格式：JSON
     * 		需要如下参数：
     *              type:设备类型，必传。1PC端前台，2PC端后台，3APP端接口，4APP端网页
     *              username：登录用户名，必传
     *              password：密码，选传，默认为空字符串
     *              phone：用户手机号，选传
     *              email：邮箱，选传
     *              invitation：邀请码，选传
     * @author xiaoyutab<xiaoyutab@qq.com>
     * @version v1.0.0
     * @copyright (c) 2017, xiaoyutab
     * @adtime 2018-03-15 17:46:27
     */
    public function regAction() {
        $param = I('post.');
        if(!isset($param['username']) || empty($param['username'])){
            // 判断username不为空且不重复
            return $this->returnCode('2');
        }
        $user = new UserModel();
        $info = $user->where(array(
            'username' => $param['username'],// 判断Username不重复
        ))->find();
        if($info){
            return $this->returnCode('3');
        }
        // 如果用户输入了手机号
        $ver = new Verification();
        if(isset($param['phone'])){
            if(!$ver->is_mobile($param['phone'])){
                return $this->returnCode('4');
            }
            // 如果手机号重复了也返回错误
            $info = $user->where(array(
                'phone' => $param['phone'],// 判断手机号不重复
            ))->find();
            if($info){
                return $this->returnCode('7');
            }
        }
        // 如果用户输入了邮箱
        if(isset($param['email'])){
            if(!$ver->is_email($param['email'])){
                return $this->returnCode('5');
            }
            // 如果邮箱重复了也返回错误
            $info = $user->where(array(
                'email' => $param['email'],// 判断邮箱不重复
            ))->find();
            if($info){
                return $this->returnCode('8');
            }
        }
        // 如果设置开启了邀请码
        if(C('API_CONF.user.invitation',NULL,FALSE)){
            // 如果邀请码为必填项
            if(C('API_CONF.user.reg_invitation',NULL,FALSE)){
                if(!isset($param['invitation']) || empty($param['invitation'])){
                    return $this->returnCode('17');
                }
            }
            // 如果邀请码设置为选传
            if(isset($param['invitation'])){
                // 如果未查到邀请码
                $info = $user->where(array(
                    'invitation' => $param['invitation'],// 判断Username不重复
                ))->find();
                if(!$info){
                    return $this->returnCode('17');
                } else {
                    $user['invitation_uid'] = $info['id'];
                }
            }
        }
        if(isset($param['invitation'])){
            unset($param['invitation']);
        }
        // 生成密码随机掩码
        $param['rand_code'] = $user->create_rand_code();
        // 处理用户密码信息
        !isset($param['password']) && $param['password'] = '';
        $param['password'] = pass($param['password'], $param['rand_code']);
        // 执行注册操作并记录注册日志
        $uid = $user->create_info($param);
        if($uid){
            (new LogModel())->user_reg($uid);// 记录注册日志
            return $this->loginAction($uid,$param);// 注册以后直接进行登录
        }
        return $this->returnCode('9999');
    }
    
    /**
     * 用户登录操作
     * 		传输方式：POST
     * 		返回参数格式：JSON
     * 		需要如下参数：
     *              username    用户名
     *              password    密码
     *              v_code      验证码
     *              type        设备类型，默认1CP端前台
     * 
     * 
     * @api {post} /User/login 01登录用户
     * @apiDescription 登录用户
     *      该用户会返回一个token值,后面需要登录的接口均需要传入该token信息
     * @apiGroup 01User
     * @apiVersion 1.0.0
     * @apiParam {string}  useename 用户名/手机号
     * @apiParam {string}  password 密码
     * @apiParam {string}  type 设备类型，默认1CP端前台,2PC端后台,3APP端,4Wap端H5页面
     * @apiSuccessExample Success-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":0,
     *      "msg":"成功",
     *      "time":"2018-06-17 14:47:18",
     *      "data":{
     *          "token":"67c0a443159f42e0ec95f872908e5b00",// token值
     *          // token值传输时需要放置在header请求头中,名称为TOKEN
     *          // 如:curl xxx/xxx -H 'TOKEN:67c0a443159f42e0ec95f872908e5b00' -d 'x:xx'
     *          "username":"admin",// 用户名
     *          "phone":"",// 用户手机号
     *          "email":"",// 用户邮箱
     *          "sex":"保密",// 用户性别
     *          "nickname":""// 用户昵称
     *      }
     *  }
     * @apiErrorExample Error-Response:
     * HTTP/1.1 200 OK
     * {
     *     "code":2,
     *     "msg":"参数错误",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-Password:
     * HTTP/1.1 200 OK
     * {
     *     "code":10,
     *     "msg":"密码输入错误",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-Dervice:
     * HTTP/1.1 200 OK
     * {
     *     "code":11,
     *     "msg":"登录设备达到上限",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-Dervice-2:
     * HTTP/1.1 200 OK
     * {
     *     "code":12,
     *     "msg":"同一类型设备登录达到上限",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-User-Check:
     * HTTP/1.1 200 OK
     * {
     *     "code":13,
     *     "msg":"该账号禁止登录",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-User-Check-2:
     * HTTP/1.1 200 OK
     * {
     *     "code":14,
     *     "msg":"该账号已申请注销",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     * @apiErrorExample Error-User-Check-3:
     * HTTP/1.1 200 OK
     * {
     *     "code":15,
     *     "msg":"该账号已注销",
     *     "time":"2018-06-15 15:05:56",
     *     "data":{
     *     }
     * }
     */
    public function loginAction($uid = false,$param = array()){
        $param || $param = I('post.');
        $user = new UserModel();
        isset($param['type']) || $param['type'] = 1;
        if($uid){
            $info = $user->get_info($uid);
            if($param['type'] == 2){
                // 后台登录需要判断有无后台登录权限
                if($info['admin_group'] < 1){
                    // 如果没有后台登录权限则直接返回失败信息
                    return $this->returnCode('20');
                }
                (new LogModel())->user_login_admin($uid);
            } else {
                (new LogModel())->user_login($uid,$param['type']);
            }
            $token = (new UserTokenModel())->create_token($uid,$param['type']);
            if(!$token){
                if($token === FALSE){
                    // 登录设备达到上限
                    return $this->returnCode('11');
                }
                // 同类设备登录达到上限
                return $this->returnCode('12');
            }
            $info['token'] = $token;
            return $this->returnCode(array(
                'token' => $info['token'],
                'username' => $info['username'],
                'phone' => $info['phone'],
                'email' => $info['email'],
                'sex' => get_config('UserSex',$info['sex']),
                'nickname' => $info['nickname'],
            ));
        }
        if(!C('API_CONF.user.vcode_pic')){
            if(!isset($param['v_code']) || !$param['v_code'] || !$this->checkVcode($param['v_code'])){
                return $this->returnCode('19');
            }
        }
        if(!isset($param['username']) || empty($param['username'])){
            // 判断username不为空且不重复
            return $this->returnCode('2');
        }
        $info = $user->where(array(
            'username|phone|email' => $param['username'],// 查询多重条件下的登录
        ))->select();
        !isset($param['password']) && $param['password'] = '';
        !isset($param['type']) && $param['type'] = 1;
        foreach($info as $k => $v){
            if($v['password'] == pass($param['password'],$v['rand_code'])){
                // 如果密码输入正确，登录用户
                return $this->loginAction($v['id'],$param);
            }
        }
        // 记录密码错误日志
        $_log = new LogModel ();
        $_log->password_error($param['username']);
        $count = $_log->where(array('user_type'=>7,'tab_key' => $param['username'],'uid'=>0,'ad_time'=>array('gt', strtotime(date('Y-m-d 00:00:01')))))->count();
        if($count > C('API_CONF.all_user.password_error')){
            // 如果达到密码错误次数上限了，返回该账户已锁定
            return $this->returnCode('18');
        }
        return $this->returnCode('10');
    }
    
    /**
     * 注销登录操作
     * 		传输方式：POST
     * 		返回参数格式：JSON
     * 		需要如下参数：
     *              token   用户登录的token值
     * 
     * @api {post} /User/logout 02退出登录
     * @apiDescription 退出登录操作
     *      该操作需要使用一个单独传输的token参数
     * @apiGroup 01User
     * @apiVersion 1.0.0
     * @apiParam {string}  token 登录token标识
     * @apiPermission TOKEN 登录标识字段
     * @apiSuccessExample Success-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":0,
     *      "msg":"成功",
     *      "time":"2018-06-17 14:47:18",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 200 OK
     *      {
     *          "code":2,
     *          "msg":"参数错误",
     *          "time":"2018-06-15 15:05:56",
     *          "data":{
     *          }
     *      }
     * @param string $token 登录的token值
     * @author xiaoyutab<xiaoyutab@qq.com>
     * @version v1.0.0
     * @copyright (c) 2017, xiaoyutab
     * @adtime 2018-03-15 17:46:27
     */
    public function logoutAction($token = ''){
        $token || $token = I('post.token');
        if(empty($token)){
            return $this->returnCode('2');
        }
        $user = new UserTokenModel();
        $uid = $user->check_token($token,true);
        if(!$uid){
            return $this->returnCode('2');
        }
        // 记录日志
        if($uid['type'] == 2){
            (new LogModel())->user_logout_admin($uid['uid']);
        } else {
            (new LogModel())->user_logout($uid['uid']);
        }
        $user->where(array('token'=>$token))->delete();
        return $this->returnCode('0');
    }

    /**
     * 获取图像验证码操作
     *      该操作会生成六位随机数字插入到数据库中
     *      查询范围为进C('API_CONF.vcode_pic.times')秒钟的数据
     * 
     * @author xiaoyutab<xiaoyutab@qq.com>
     * @version v1.0.0
     * @copyright (c) 2017, xiaoyutab
     * @adtime 2018-04-12 16:54:36
     */
    public function getVcodeAction(){
        $ver = new Verify();
        $ver->codeSet = '0123456789';
        $ver->bg = array(245,245,245);
        $ver->length = 4;
        $ver->useCurve = FALSE;
        $ver->useNoise = FALSE;
        $ver->fontttf = '9.ttf';
        $ver->entry();
        // 获取生成的验证码
        $_code = new UserCodeModel();
        $_code->create_info(array(
            'code' => $ver->v_code,
        ));
    }
    
    /**
     * 识别验证码信息
     * 
     * @param string $code 验证码的值
     * @param string $par 设置的手机/邮箱等辅助值
     * @param boolean $bj 是否标记为已使用状态
     * @return boolean 是否存在该值
     * @author xiaoyutab<xiaoyutab@qq.com>
     * @version v1.0.0
     * @copyright (c) 2017, xiaoyutab
     * @adtime 2018-04-12 17:15:34
     */
    public function checkVcode($code,$par = '',$bj = false){
        $_code = new UserCodeModel();
        $code_list = $_code->where(array(
            'code' => $code,
            'ad_time' => array('GT',NOW_TIME - C('API_CONF.vcode_pic.times')),
            'status' => 99,
        ))->select();
        if(empty($code_list)){
            return FALSE;
        }
        foreach($code_list as $v){
            if(!empty($par)){
                // 如果设置的par不为空
                if($v['times'] == $par){
                    if($bj){
                        $_code->set_field($v['id']);
                    }
                    return TRUE;
                }
            } else {
                if(!empty($v)){
                    if($bj){
                        $_code->set_field($v['id']);
                    }
                    return TRUE;
                }
            }
        }
        return FALSE;
    }
    
    /**
     * @api {post} /User/get_customer 03获取我的客户列表
     * @apiDescription 获取我的客户列表
     * @apiGroup 01User
     * @apiPermission token
     * @apiVersion 1.0.0
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *          "count": "2",// 查询到的条数
     *          "list": [// 查询到的数据信息
     *              {
     *                  "id": "2",// 客户编号ID
     *                  "name": "测试分类",// 客户姓名
     *                  "phone": "14563453233",// 客户手机号
     *                  "company": "分析报告"// 客户公司
     *              },
     *              {
     *                  "id": "1",
     *                  "name": "测试",
     *                  "phone": "14563453233",
     *                  "company": "分析报告"
     *              }
     *          ]
     *      }
     *  }
     * @apiSuccessExample Success-Empty:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *          "count": "0",// 查询到的条数
     *          "list": [// 查询到的数据信息
     *          ]
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *      HTTP/1.1 200 OK
     *      {
     *          "code":2,
     *          "msg":"参数错误",
     *          "time":"2018-06-20 23:33:11",
     *          "data":{
     *          }
     *      }
     */
    public function get_customerAction(){
        $u_info = $this->check_token();
        $customer = new UserCustomerModel();
        $list = $customer->where([
            'uid' => $u_info['id'],
        ])->getList(0,999);
        $return_data = [];
        foreach($list as $v){
            $return_data[] = [
                'id' => $v['id'],
                'name' => $v['name'],
                'phone' => $v['phone'],
                'company' => $v['company'],
            ];
        }
        return $this->returnCode([
            'count' => count($return_data),
            'list' => $return_data
        ]);
    }
    
    /**
     * @api {post} /User/create_customer 04创建我的客户
     * @apiDescription 创建我的客户
     * @apiGroup 01User
     * @apiPermission token
     * @apiParam {string} name 客户名称
     * @apiParam {string} phone 客户手机/电话
     * @apiParam {string} company 客户所属公司名称
     * @apiVersion 1.0.0
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":2,
     *      "msg":"参数错误",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Name:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":22,
     *      "msg":"姓名已存在",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Service-Error:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":9999,
     *      "msg":"系统错误",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     */
    public function create_customerAction(){
        $u_info = $this->check_token();
        $customer = new UserCustomerModel();
        $list = $customer->where([
            'uid' => $u_info['id'],
            'name' => I('post.name','','trim'),
        ])->getList(0,999);
        if(!empty($list)){
            // 如果查询到该姓名了就直接返回错误信息
            return $this->returnCode('22');
        }
        $post = I('post.');
        $post['uid'] = $u_info['id'];
        if($customer->create_info($post)){
            return $this->returnCode('0');
        } else {
            return $this->returnCode('9999');
        }
    }
    
    /**
     * @api {post} /User/delete_customer 05删除我的客户
     * @apiDescription 删除我的客户。修复删除我的客户时一直提示参数错误的BUG
     * @apiGroup 01User
     * @apiPermission token
     * @apiParam {integer} id 我的客户编号ID
     * @apiVersion 1.0.1
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":2,
     *      "msg":"参数错误",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     */
    public function delete_customerAction(){
        $u_info = $this->check_token();
        $customer = new UserCustomerModel();
        if($customer->where(['uid'=>$u_info['id']])->setDelete(I('post.id'))){
            return $this->returnCode('0');
        } else {
            return $this->returnCode('2');
        }
    }
    
    /**
     * @api {post} /User/update_customer 06修改我的客户
     * @apiDescription 修改我的客户
     * @apiGroup 01User
     * @apiPermission token
     * @apiParam {integer} id 我的客户编号ID
     * @apiParam {string} name 客户名称
     * @apiParam {string} phone 客户手机/电话
     * @apiParam {string} company 客户所属公司名称
     * @apiVersion 1.0.0
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":2,
     *      "msg":"参数错误",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     */
    public function update_customerAction(){
        $u_info = $this->check_token();
        $customer = new UserCustomerModel();
        $post = I('post.');
        $customer->where([
            'id' => $post['id'],
            'uid' => $u_info['id'],
            'status' => array('neq',98),
        ])->save($post);
        return $this->returnCode('0');// 此处不判断修改是否成功，直接统一按照成功处理【除非用户未登录】
    }
    
    /**
     * @api {post} /User/update_password 07修改我的密码
     * @apiDescription 修改我的密码
     * @apiGroup 01User
     * @apiPermission token
     * @apiParam {string} old_password 用户的登录密码
     * @apiParam {string} password 用户输入的密码
     * @apiParam {string} password_check 用户输入的确认密码
     * @apiVersion 1.0.1
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":9,
     *      "msg":"两次密码输入不一致",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Service-Error:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":1,
     *      "msg":"失败",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     */
    public function update_passwordAction(){
        $u_info = $this->check_token();
        $p_1 = I('post.password');
        $p_2 = I('post.password_check');
        $old_password = I('post.old_password');
        if($p_1 != $p_2){
            // 如果两次密码输入不一致则直接返回错误信息
            return $this->returnCode('9');
        }
        if(empty($old_password)){
            return $this->returnCode(10);
        }
        if(pass($old_password,$u_info['rand_code']) != $u_info['password']){
            return $this->returnCode(10);
        }
        $user = new UserModel();
        $r_code = $user->create_rand_code();// 生成随机码
        $pass = pass($p_2, $r_code);// 根据随机码来生成密码
        // 执行更新密码操作
        // 只允许正常用户执行修改密码操作
        $status = $user->where(['id'=>$u_info['id'],'status'=>99])->save([
            'password' => $pass,
            'rand_code' => $r_code,
        ]);
        if($status){
            $this->logoutAction($_SERVER['HTTP_TOKEN']);
            return $this->returnCode('0');
        }
        return $this->returnCode('1');
    }
    
    /**
     * @api {post} /User/update_user_info 08修改我的个人信息
     * @apiDescription 修改我的个人信息,但是修改密码后会退出登录状态。当前版本添加逻辑:如果传空则排除某字段信息
     * 
     * 当前版本(1.0.2)修复了能直接修改登录用户名username的bug
     * @apiGroup 01User
     * @apiPermission token
     * @apiParam {string} phone 用户手机号【可用来登录】
     * @apiParam {string} nickname 用户昵称
     * @apiVersion 1.0.2
     * @apiSuccessExample Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code": "0",
     *      "msg": "成功",
     *      "time": "2018-06-21 17:04:06",
     *      "data": {
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":23,
     *      "msg":"项目无变化",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Service-Error:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":1,
     *      "msg":"失败",
     *      "time":"2018-06-20 23:33:11",
     *      "data":{
     *      }
     *  }
     */
    public function update_user_infoAction(){
        $post = I('post.');// 获取POST提交过来的数据
        $u_info = $this->check_token();// 检测登录并获取个人信息
        $user = new UserModel();
        $user_info = new UserInfoModel();
        foreach($post as $k => $v){
            if(empty($v)){
                unset($post[$k]);
            }
        }
        if(isset($post['username'])){
            unset($post['username']);
        }
        $s1 = $user->where(['id'=>$u_info['id']])->save($post);
        $s2 = $user_info->where(['id'=>$u_info['id']])->save($post);
        if($s1 || $s2){
            return $this->returnCode([]);
        }
        return $this->returnCode('23');
    }
    
    /**
     * 获取用户信息
     * 
     * @api {post} /User/get_user_info 09获取用户信息
     * @apiDescription 获取用户信息
     * @apiGroup 01User
     * @apiPermission token
     * @apiVersion 1.0.0
     * @apiSuccessExample Success-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":0,
     *      "msg":"成功",
     *      "time":"2018-06-17 14:47:18",
     *      "data":{
     *          "username":"admin",// 用户名
     *          "phone":"",// 用户手机号
     *          "email":"",// 用户邮箱
     *          "sex":"保密",// 用户性别
     *          "nickname":""// 用户昵称
     *      }
     *  }
     * @apiErrorExample Error-Response:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":2,
     *      "msg":"参数错误",
     *      "time":"2018-06-15 15:05:56",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-User:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":21,
     *      "msg":"用户未登录",
     *      "time":"2018-06-15 15:05:56",
     *      "data":{
     *      }
     *  }
     * @apiErrorExample Error-Server:
     *  HTTP/1.1 200 OK
     *  {
     *      "code":9999,
     *      "msg":"系统错误",
     *      "time":"2018-06-15 15:05:56",
     *      "data":{
     *      }
     *  }
     */
    public function get_user_infoAction(){
        $info = $this->check_token();// 检测登录并获取个人信息
        return $this->returnCode(array(
            'username' => $info['username'],
            'phone' => $info['phone'],
            'email' => $info['email'],
            'sex' => get_config('UserSex',$info['sex']),
            'nickname' => $info['nickname'],
        ));
    }
}
